﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// 根据品种编号搜索所有需求，并自动进行累计
    /// 选择进入需要创建采购单或生产单队列，
    /// 创建生产单
    /// 创建留位关系
    /// </summary>
    public partial class TDIWD02
    {
        #region ==IsAll===========
        public static readonly DependencyProperty IsAllProperty = DependencyProperty.Register("IsAll",
        typeof(bool), typeof(TDIWD02),
        new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsAllChanged));
        public bool IsAll
        {
            get
            {
                return (bool)GetValue(IsAllProperty);
            }
            set
            {
                SetValue(IsAllProperty, value);
                OnShowALLChg(value);
            }
        }
        private static void OnIsAllChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as TDIWD02;
            if (src != null)
            {
                src.IsAll = (bool)e.NewValue;
            }
        }
        #endregion
        public TDIWD02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWDECK();
            DataContext = MV;
            InitializeComponent();
         }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if (dwMaster == null)
            {
                ABAUF = "";
                return;
            }
            ABAUF = "V"+dwMaster["WDAUFKRS"].ToString() + dwMaster["WDAUFLFD"].ToString() + dwMaster["WDAUFPOS"].ToString() + dwMaster["WDUPOS"].ToString() + "DI ";
        }  
        public override void OnEXAUFChg(string vlaue)
        {
            TBMain.Clear();
            if (vlaue.Length < 62)
                return;
            dwData = TBMain.NewRow();
            dwData["WDMANDANT"] = app.Mandant;
            dwData["WDSA"] = WDSA;
            dwData["WDTYP"] = WZTYP;
            dwData["WDWAKZ"] =ARTST;
            dwData["WDART"] = vlaue.Substring(1, 20);
            dwData["WDVAR"] = vlaue.Substring(21, 2);
            dwData["WDFARBE"] = vlaue.Substring(23, 10); 
            dwData["WDBESCHICH"] = vlaue.Substring(33, 10);
            dwData["WDDESS"] = vlaue.Substring(43, 10);
            dwData["WDCOLORIT"] = vlaue.Substring(53, 10);
            if (WZTYP == "N")
            {
                dwData["WDKUNDNR"] = " AND WDZUGET + WDRESERV < WDBEDARF";
            }
            else
            {
                dwData["WDKUNDNR"] = "";
            }
            dwData["WDBEDST"] = " AND ABPAUFART='"+AUFART+"'";
            SResult = TMV.QWD28(dwData);
            MergeData(SResult, true);
            IsAll = !IsAll;
            IsAll = !IsAll;
            base.OnEXAUFChg(vlaue);
        }
       public virtual void OnShowALLChg(bool _IsShowAll)
        {
            if (vwMaster.View == null)
                return;
            if(!_IsShowAll)
            {
                filter = "ABAVKAUFKRS='"+EXAUF.Substring(64,2)+"' AND ABAVKAUFLFD='"+EXAUF.Substring(66,6)+"' AND ABAVKAUFPOS='"+EXAUF.Substring(72,3)+"'";
                cvMaster.CustomFilter = filter;
                vwMaster.View.MoveCurrentToFirst();
            }
            else
            {
                cvMaster.CustomFilter = null;
            }
        } 
    }
}
